<?php

$loot = file_get_contents("LootList.txt");

//$lootsplit = split('\/n/r', $loot);

$sql_file = fopen("lootsql.sql", "w+");

foreach(explode(chr(10), $loot) as $lootline) {

if(preg_match('/\[loottemplate (.*?)\]/', $lootline)){
preg_match_all("/\[loottemplate (.*?)\]/", $lootline, $loottemplate_temp);
$loottemplate = $loottemplate_temp[1][0];
}

if(preg_match('/loot=(.*?)/', $lootline)){
preg_match_all("/loot=(.*?) (.*) \/\/(.*)/", $lootline, $lootline_temp);

$item = $lootline_temp[1][0];
$chance = $lootline_temp[2][0];

$sql_line = "insert into `creature_loot_template` ( `entry`, `item`, `chance`, `questchance`) values ( '$loottemplate', '$item', '$chance', '0');";
fwrite($sql_file, $sql_line .chr(10));
}

}
fclose($sql_file);
?>